package com.jdbc;

import com.alibaba.druid.pool.DruidDataSourceFactory;

import javax.sql.DataSource;
import java.io.IOException;
import java.sql.Connection;
import java.util.Properties;

public class DruidDemo {

    public static void main(String[] args) {
        //创建Properties对象，用于读取配置文件
        Properties properties = new Properties();
        try {
            //加载src下的配置文件
            properties.load(DruidDemo.class.getClassLoader().getResourceAsStream("druid.properties"));
//            properties.load(new FileInputStream("D:\\java_code\\java02_jdbc\\src\\druid.properties"));
            //创建数据源
            DataSource dataSource = DruidDataSourceFactory.createDataSource(properties);
            //通过数据源创建连接
            Connection connection = dataSource.getConnection();
            System.out.println(connection);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
